<template>
  <div>
    Option Table
    <TView
      :display="displayProp"
      :closingDate="closingDate"
      :executionPrice="executionPrice"
    >
      <TViewList ctype="call" :list="callList" #default="{ c1 }">
        {{ c1 | fmt("date") }}
      </TViewList>
      <template #price="{ price }"> {{ price | numFmt(2) }} </template>
      <TViewList ctype="pull" :list="pullList" #default="{ c1 }">
        {{ c1 | fmt(displayProp) }}
      </TViewList>
    </TView>
    <div></div>
    <el-button @click="changeDisplay()">{{ displayProp }}</el-button>
  </div>
</template>

<script>
import TView from "@/components/T";
import TViewList from "@/components/T/TViewList";
import { mapState } from "vuex";

export default {
  components: {
    TView,
    TViewList,
  },
  data() {
    return {
      displayProp: "contractPrice",
    };
  },
  computed: mapState({
    callList: (state) => state.contract.callList,
    pullList: (state) => state.contract.pullList,
    closingDate: (state) => state.contract.closingDate,
    executionPrice: (state) => state.contract.executionPrice,
  }),
  created() {
    this.$store.dispatch("contract/loadContractData", {});
  },
  filters: {
    fmt(obj, display) {
      if (!obj) return "-";
      return obj[display];
    },
    numFmt(num, precision) {
      return num.toFixed(precision);
    },
  },
  methods: {
    changeDisplay() {
      this.displayProp = this.displayProp == "date" ? "contractPrice" : "date";
    },
  },
};
</script>